<?php
namespace app\api\logic;
use think\Cache;
use think\Request;
use app\api\validate\Login as LoginValidate;
/**
 * Class descript.
 * User: chan
 * Date: 2017/10/26 15:30
 */
class Login extends \app\api\BaseModel
{
    /**
     * 用户登陆
     * @return array
     */
    public function login()
    {
       // (new LoginValidate())->checkLoginParam();
        if(!isset($this->requestData['mobile'])){
            return array('message'=>'手机号码必传');
        }
        if(!isset($this->requestData['code'])){
            return array('message'=>'验证码必传');
        }
        $condition['mobile'] = $this->requestData['mobile'];
        $condition['status'] = 1;
        $root = db('member')->where($condition)->find();
        if(!$root) return array('message'=>'账号不存在');
        if($root['status'] != 1) return array('message'=>'账号异常');
        //if(Cache::get("code") != base64_encode($this->requestData['code'])) return array('message' => '验证码不正确错误');
        $Oauth2 =  new \app\api\service\Oauth2();
        $user=array(
            ""=>$root['id'],
        );
        //返回生成token
        return $Oauth2::generateToken($user);
    }
}